package com.chunfeng.controller;

import com.chunfeng.entity.Orders;
import com.chunfeng.result.JsonRequest;
import com.chunfeng.result.ServiceController;
import com.chunfeng.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单Controller
 *
 * @author by 春风能解释
 * <p>
 * 2022/12/20
 */
@RestController
@RequestMapping("/orders")
public class OrdersController extends ServiceController {

    /**
     * 订单业务层注入
     */
    @Autowired
    private IOrdersService ordersService;

    /**
     * 查看所有订单信息
     *
     * @return JSON
     */
    @GetMapping
    public JsonRequest<List<Orders>> lookAllOrders() {
        return ordersService.lookAllOrders();
    }

    /**
     * 按条件获取订单信息
     *
     * @param orders 条件
     * @return JSON
     */
    @PostMapping("/con")
    public JsonRequest<List<Orders>> lookOrdersByCondition(@RequestBody Orders orders) {
        return ordersService.lookOrdersByCondition(orders);
    }


    /**
     * 新增一条订单信息
     *
     * @param orders 订单信息
     * @return JSON
     */
    @PostMapping
    public JsonRequest<Integer> insertOneOrders(@RequestBody Orders orders) {
        return ordersService.insertOneOrder(orders);
    }

    /**
     * 修改一条订单信息
     *
     * @param orders 订单信息
     * @return JSON
     */
    @PutMapping
    public JsonRequest<Integer> updateOneOrders(@RequestBody Orders orders) {
        return ordersService.updateOneOrder(orders);
    }

    /**
     * 删除订单信息
     *
     * @param ids ID值
     * @return JSON
     */
    @DeleteMapping
    public JsonRequest<Integer> deleteOrders(@RequestBody Integer[] ids) {
        return ordersService.deleteOrder(ids);
    }
}
